package cn.ds.assets.module.assets.dal.mysql.metadataModelTechnology;

import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDate;

import cn.ds.assets.framework.common.pojo.PageResult;
import cn.ds.assets.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ds.assets.framework.mybatis.core.mapper.BaseMapperX;
import cn.ds.assets.module.assets.dal.dataobject.metadataModelTechnology.BaseMetadataModelTechnologyDO;
import org.apache.ibatis.annotations.Mapper;
import cn.ds.assets.module.assets.controller.admin.metadataModelTechnology.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 元数据管理-元模型-技术属性 Mapper
 *
 * @author admin
 */
@Mapper
public interface BaseMetadataModelTechnologyMapper extends BaseMapperX<BaseMetadataModelTechnologyDO> {

    default PageResult<BaseMetadataModelTechnologyDO> selectPage(BaseMetadataModelTechnologyPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BaseMetadataModelTechnologyDO>()
                .eqIfPresent(BaseMetadataModelTechnologyDO::getSort, reqVO.getSort())
                .likeIfPresent(BaseMetadataModelTechnologyDO::getAttrName, reqVO.getAttrName())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getAttrDesc, reqVO.getAttrDesc())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getRange, reqVO.getRange())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getRequired, reqVO.getRequired())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getReadOnly, reqVO.getReadOnly())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getCreateBy, reqVO.getCreateBy())
                .betweenIfPresent(BaseMetadataModelTechnologyDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getUpdateBy, reqVO.getUpdateBy())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getModelId, reqVO.getModelId())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getModuleType, reqVO.getModuleType())
                .inIfPresent(BaseMetadataModelTechnologyDO::getId,reqVO.getIds())
                .orderByDesc(BaseMetadataModelTechnologyDO::getId));
    }

    default List<BaseMetadataModelTechnologyDO> selectList(BaseMetadataModelTechnologyExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BaseMetadataModelTechnologyDO>()
                .eqIfPresent(BaseMetadataModelTechnologyDO::getSort, reqVO.getSort())
                .likeIfPresent(BaseMetadataModelTechnologyDO::getAttrName, reqVO.getAttrName())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getAttrDesc, reqVO.getAttrDesc())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getRange, reqVO.getRange())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getRequired, reqVO.getRequired())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getReadOnly, reqVO.getReadOnly())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getCreateBy, reqVO.getCreateBy())
                .betweenIfPresent(BaseMetadataModelTechnologyDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getUpdateBy, reqVO.getUpdateBy())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getModelId, reqVO.getModelId())
                .eqIfPresent(BaseMetadataModelTechnologyDO::getModuleType, reqVO.getModuleType())
                .inIfPresent(BaseMetadataModelTechnologyDO::getId,reqVO.getIds())
                .orderByDesc(BaseMetadataModelTechnologyDO::getId));
    }

    @Update("UPDATE assets_metadata_model_technology SET deleted = 1, update_time = #{deletedTime} WHERE id = #{id}")
    void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);
}
